
const Empty = [null, "", "null", undefined, "undefined"];
  const ROOT_PATH = "/api";

const jsutils = {
    gettootpath() {
        return ROOT_PATH;
    },
    getquerystring(name) {
        return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || ''
    },
    isdate(str) {
        if (str.length != 0) {
            let reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;
            let r = str.match(reg);
            if (r == null)
                return false;
            else
                return true;
        }
        return false;
    },
    isdatetime(str) {
        if (str.length != 0) {
            let reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
            let r = str.match(reg);
            if (r == null) return false; else return true
        }
        return false
    },
    isletter(str) {
        if (str.length != 0) {
            let reg = /^[a-zA-Z]+$/;
            if (!reg.test(str)) return fasle; else return true;
        }
        return false;
    },
    isinteger(str) {
        if (str.length != 0) {
            let reg = /^[-+]?\d*$/;
            if (!reg.test(str)) return false; else return true;
        }
        return false;
    },
    isdouble(str) {
        if (str.length != 0) {
            let reg = /^[-\+]?\d+(\.\d+)?$/;
            if (!reg.test(str)) return false; else return true;

        }
        return false;
    },
    isstring(str) {
        if (str.length != 0) {
            let reg = /^[a-zA-Z0-9_]+$/;
            if (!reg.test(str)) return false; else return true;

        }
        return false;
    },
    ischinese(str) {
        if (str.length != 0) {
            let reg = /^[\u0391-\uFFE5]+$/;
            if (!reg.test(str)) return false; else return true;
        }
        return false;
    },
    Isemail(str) {
        if (str.length != 0) {
            let reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
            if (!reg.test(str)) return false; else return true;
        }
        return false;
    },
    iscardno(str) {
        // 身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X 
        let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
        return reg.test(str)

    },
    iszip(str) {
        if (str.length != 0) {
            let reg = /^\d{6}$/;
            if (!reg.test(str)) return false; else return true;
        }
        return false;
    },
    checknumber(e) {
        var keynum = window.event ? e.keyCode : e.which;
        if ((48 <= keynum && keynum <= 57) || keynum == 8) {
            return true;
        } else {
            return false;
        }
    },
    checkforfloat(obj, e) {
        var isOK = false;
        var key = window.event ? e.keyCode : e.which;
        if ((key > 95 && key < 106) || //小键盘上的0到9  
            (key > 47 && key < 60) ||  //大键盘上的0到9  
            (key == 110 && obj.value.indexOf(".") < 0) || //小键盘上的.而且以前没有输入.  
            (key == 190 && obj.value.indexOf(".") < 0) || //大键盘上的.而且以前没有输入.  
            key == 8 || key == 9 || key == 46 || key == 37 || key == 39) {
            isOK = true;
        } else {
            if (window.event) { //IE
                e.returnValue = false;   //event.returnValue=false 效果相同.    
            } else { //Firefox 
                e.preventDefault();
            }
        }
        return isOK;
    },
    checkemail(obj) {

        let reyx = "^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$";
        //let reyx = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
        return (reyx.test(obj));

    },
    checkreg(obj) {
        let regString = /[a-zA-Z]+/;
        return (regString.test(obj));
    },
    fordight(Dight, How) {
        Dight = Math.round(Dight * Math.pow(10, How)) / Math.pow(10, How);
        return Dight;
    },
    isempty(str) {
        //true  空
        return Empty.includes(str);
    },
    isphone(str) {
        let phoneNumReg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
        return (phoneNumReg.test(str));

    },
    decode(str) {
        return window.atob(str)
    },
    encrypt(str) {
        return window.btoa(str)
    },
    decodeatob(str) {
        return decodeURIComponent(window.atob(str))
    },
    storageset(key, value) {
        window.localStorage.setItem(key, JSON.stringify(value));
    },
    storageget(key) {
        let Storagemodel = window.localStorage.getItem(key)

        return JSON.parse(Storagemodel);
    },
    storageremove(key) {
        window.localStorage.removeItem(key);
    },
    sessionset(key, value) {
        window.sessionStorage.setItem(key, JSON.stringify(value));
    },
    sessionget(key) {
        let sessmodel = window.sessionStorage.getItem(key);


        return JSON.parse(sessmodel);
    },
    sessionremove(key) {
        window.sessionStorage.removeItem(key);
    },
    openurl(str) {
        window.open(str);
    },


    isIE() {
        if (!!window.ActiveXObject || "ActiveXObject" in window)
            return true;
        else
            return false;
    },
    //获取guid
    S4() {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
    },
    getguid(type) {
        if (!!type && type.toUpperCase() == 'N')
            return (this.S4() + this.S4() + this.S4() + this.S4() + this.S4() + this.S4() + this.S4() + this.S4());

        return (this.S4() + this.S4() + "-" + this.S4() + "-" + this.S4() + "-" + this.S4() + "-" + this.S4() + this.S4() + this.S4());
    },
    //end

    //获取随机数
    randomNum(minNum, maxNum) {
        switch (arguments.length) {
            case 1:
                return parseInt(Math.random() * minNum + 1, 10);
                break;
            case 2:
                return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
                break;
            default:
                return 0;
                break;
        }
    },

};
export default jsutils


